package com.jlboot.core;

import com.jfinal.kit.PropKit;
import lombok.extern.slf4j.Slf4j;

import java.util.Properties;

/**
 * Created by 51594 on 2022/7/27.
 */
@Slf4j
public class ConfigUtil {


    /**
     * 读取 WEB_HOST
     *
     * @return
     */
    public static String getWebHost() {
        return getProperty("WEB_HOST")==null?"":getProperty("WEB_HOST");
    }

    /**
     * 读取 WEB_PATH
     *
     * @return
     */
    public static String getWebPath() {
        return getProperty("WEB_PATH")==null?"":getProperty("WEB_PATH");
    }

    /**
     * 读取 ADMIN_PATH
     *
     * @return
     */
    public static String getWebAdminPath() {
        return getProperty("ADMIN_PATH")==null?"":getProperty("ADMIN_PATH");
    }

    /**
     * 读取 ADMIN_PATH
     *
     * @return
     */
    public static String getWebAdminLoginPath() {
        return getWebAdminPath() + "/login";
    }


    /**
     * 取web-info路经
     *
     * @return
     */
    public static String getWebInfoPath() {
        String path = ConfigUtil.class.getResource("/").getPath();
        return path;
    }

    /**
     * 判断 是否debug
     *
     * @return
     */
    public static boolean DEBUG() {
        return "true".equals(getProperty("DEBUG"));
    }

    /**
     * 判断 是否debug
     *
     * @return
     */
    public static boolean READONLY() {
        return "true".equals(getProperty("READONLY"));
    }

    /**
     * 是否linux
     *
     * @return
     */
    public static boolean isLinux() {
        Properties props = System.getProperties(); //
        String osName = props.getProperty("os.name").toLowerCase(); //
        if (osName.contains("windows")) {
            return false;
        } else {
            return true;
        }
    }

    /**
     * 是否windows
     *
     * @return
     */
    public static boolean isWindows() {
        Properties props = System.getProperties(); //
        String osName = props.getProperty("os.name").toLowerCase(); //
        if (osName.contains("windows")) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 读取属性值
     *
     * @param propName
     * @return
     */
    public static String getProperty(String propName) {
        return PropKit.get(propName);
    }


    /**
     * 读取属性值
     *
     * @param propName
     * @return
     */
    public static String getProperty(String propName, String defaultValue) {
        String value = PropKit.get(propName);
        return value == null ? defaultValue : value;
    }

}
